﻿using System;
using System.Web.Helpers;
using System.Web.Mvc;
using TuanAnhPersonalWeb.Models;

namespace TuanAnhPersonalWeb.Controllers
{
    public class ContactController : Controller
    {
        //
        // GET: /Contact/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(Contact contact)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    WebMail.SmtpServer = "smtp.gmail.com";
                    WebMail.SmtpPort = 587;
                    WebMail.EnableSsl = true;
                    WebMail.UserName = "trongnghia206@gmail.com";
                    WebMail.Password = "thienduongmo";
                    WebMail.From = "trongnghia206@gmail.com";
                    string content = "----------Feedback from TuanAnh Website----------<br/>"
                                     + "Name: " + contact.Client
                                     + "<br/>Email: " + contact.Email
                                     + "<br/>Content Feedback Name: " + contact.ContentName
                                     + "<br/>Content Feedback: " + contact.Content;
                    WebMail.Send("trongnghia206@yahoo.com", "Feedback From TuanAnh Website", content);
                }
                catch (Exception)
                {
                    return View("Error");

                }
                return RedirectToAction("Index", "Home");
            }
            else
            {
                return View();
            }
        }
    }
}
